/**
 * Copyright (c) 2018-2099, Chill Zhuang 庄骞 (bladejava@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.common.tool;

import cn.hutool.core.date.DateUtil;

/**
 * 通用工具类
 *
 * @author Chill
 */
public class CommonUtil {
	//"yyyy-MM-dd 00:00:00"
	public static final String START_DATE_FORMAT = "yyyy-MM-dd 00:00:00";
	/// yyyyMMddHHmmss
	public static final String DATE_TIME_FORMAT = "yyyyMMddHHmmss";


	/**
	 * 获取当月有多少天
	 * @param year
	 * @param month
	 * @return
	 */
	public static int getDaysByYearMonth(int year, int month) {
		// 是否润年
		boolean isLeapYear = DateUtil.isLeapYear(year);
		// 获取 time 这个月有多少天
		return DateUtil.lengthOfMonth(month, isLeapYear);
	}

	/**
	 * 获取当月有多少天
	 * @param time
	 * @param format
	 * @return
	 */
	public static int getDays(String time, String format) {
		int year = Integer.parseInt(DateUtil.format(DateUtil.parse(time, format), "yyyy"));
		int month = Integer.parseInt(DateUtil.format(DateUtil.parse(time, format), "MM"));
		return getDaysByYearMonth(year, month);
	}

}
